function newPage(pagenum) {
  return new Promise((resolve, reject) => {
    var xhr = new XMLHttpRequest()
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4) {
        if (xhr.status >= 200 && xhr.status <= 304) {
          resolve(xhr.response)

        }
      }
    }
    xhr.open('GET', 'http://localhost:8888/wmp/v3.1/?p0=117&p1=searchNewsKeywordsList&pagesize=12&order=sIdxTime&r0=cors&r1=NewsObj&type=iTag&id=6521&source=web_PC&page=' + pagenum)
    xhr.send()
  })
}
let pagenum = 1

newPage(pagenum).then(result => {
  var arr = JSON.parse(result)
  var str = ``
  arr.msg.result.forEach(element => {
    str += `
            <li class="content-it">
            <a class="content-in" href="">
              <div class="content-pic">
                <div class="content-img">
                  <img src="${element.sIMG}" alt="">
                </div>
                <div class="content-placehoder">
                  <img src="./img/placeholder.webp" alt="">
                </div>
              </div>
              <h2 class="tit-content-article">${element.sTitle}</h2>
              <p class="content-tag">人才招聘</p>
              <div class="content-if">
                <p class="content-view content-view-count">
                  <i class="i-view"></i>${element.iTotalPlay}
                  <span class="content-like">
                    <i class="i-like"></i>35
                  </span>
                </p>
                <p class="content-date">
                  <span class="content-author">${element.sAuthor} </span>${element.sIdxTime.substr(0, 10)}
                </p>
              </div>
            </a>
          </li>
            `
  })
  document.querySelectorAll('.lis-content-show')[0].innerHTML += str

  // console.log(JSON.parse(result))
  // console.log(typeof result);
}).catch(error => {
  console.log(error);
})


function wait() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve('f1 3秒后执行');
    }, 3000);
  })
}




let newlist = document.querySelectorAll('.lis-content-show')[0]
window.addEventListener('scroll', () => {
  // var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  // console.log("滚动距离" + scrollTop);
  if (document.documentElement.scrollTop +
    window.innerHeight ==
    document.documentElement.scrollHeight) {
    setTimeout(() => {
      if (document.documentElement.scrollTop +
        window.innerHeight ==
        document.documentElement.scrollHeight) {
        console.log('pagenum=' + pagenum);
        pagenum++
        let newheight = newlist.offsetHeight
        newheight += 1940
        newlist.style.height = newheight + 'px'
        console.log(newheight);
        newPage(pagenum).then(result => {
          var arr = JSON.parse(result)
          var str = ``
          arr.msg.result.forEach(element => {
            str += `
            <li class="content-it">
            <a class="content-in" href="">
              <div class="content-pic">
                <div class="content-img">
                  <img src="${element.sIMG}" alt="">
                </div>
                <div class="content-placehoder">
                  <img src="./img/placeholder.webp" alt="">
                </div>
              </div>
              <h2 class="tit-content-article">${element.sTitle}</h2>
              <p class="content-tag">人才招聘</p>
              <div class="content-if">
                <p class="content-view content-view-count">
                  <i class="i-view"></i>${element.iTotalPlay}
                  <span class="content-like">
                    <i class="i-like"></i>35
                  </span>
                </p>
                <p class="content-date">
                  <span class="content-author">${element.sAuthor} </span>${element.sIdxTime.substr(0, 10)}
                </p>
              </div>
            </a>
          </li>
            `
          })
          document.querySelectorAll('.lis-content-show')[0].innerHTML += str

          // console.log(JSON.parse(result))
          // console.log(typeof result);
        }).catch(error => {
          console.log(error);
        })
      }

    }, 2000);

  }

})

